#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;
void showpending()
{   
    sigset_t set;
    sigpending(&set);
        cout << "未决信号集：";
    for (int i = 1; i <= 31; i++)
    {
        if (sigismember(&set, i))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout<<endl; 
}
void handle(int signo)
{
    cout<<"执行了"<<signo<<endl;

}
int main()
{
    signal(2,handle);
    cout<<"pid"<<getpid()<<endl;
    sigset_t set, oset;
    sigemptyset(&set);
    sigemptyset(&oset);
    sigaddset(&set, 2);
    sigprocmask(SIG_BLOCK, &set, &oset);
    int cnt=0;
    while (true)
    {
        showpending();
        sleep(1);

        if(cnt++==10)
        {
            sigprocmask(SIG_SETMASK, &oset, nullptr);
        }

    }

    return 0;
}